<?php									
/* :TODO: use configuration file to set default country */
$defaultCountryId = 412; /* New Zealand */
/* :TODO: wrapper for POST values to protect against most input issues */
$countryId = $_POST['country'];
/* :TODO: helper for default values */
if (!$countryId) {
	$countryId = $defaultCountryId;
}

$sql = 'select `ID`, `Name` from Country order by `Name` ASC';
$result = $db->query($sql);

$countryOptions = '';
if($db->rowCount($result)!= 0) {
	while ($row = $db->fetch($result)) {
		/* :TODO: Form helper for selected options */
		$selected = '';
		if($row['ID'] == $countryId) {
			$selected = ' selected="selected"';
		}
		$countryOptions .= '<option value="' . $row['ID'] . '"' . $selected . '>';
		$countryOptions .= $row['Name'] . '</option>';
	}
}
$db->free($result);
?>
<li>
            <p class="introtext">Thank You for choosing to leave a message on this page. Please follow the prompts to leave your message. It's simple and FREE.</p>
            <p class="introtext">
             <?php echo "<a href=\"remembrance.php?personid=".$_GET['personid']."\">Go back to the Remembrance Page for ".$fullName."</a>";
             ?>
            </p>
				</li>
				<li class="messageheader">
					<h2>Leave a Message</h2>
				</li>
				<li>
					<form id="messageform" method="post" action="leaveamessage.php?personid=<?php echo $_GET['personid']; ?>">
						<input type="hidden" value="posted" name="post" id="post" />
						<label for="rb1" class="rdcblabel" >Heading</label><input type="text" name="heading" id="heading" value="<?php echo stripslashes($_POST['heading']); ?>" class="large"/>
						<label for="rb2" class="rdcblabel" >Message<br/><small><span id="count">0</span>/1000 Characters</small></label>
						<textarea onkeydown="textCount();" onkeyup="textCount();" rows="10" name="comment" id="comment"><?php echo stripslashes($_POST['comment']); ?></textarea>
						<label for="rb3" class="rdcblabel" >Choose Clipart</label>
						<ul class="clipart">
						    <?php
								for ($i = 1; $i < 150; $i++) {
									if($i == $_POST['clipart']) {
										echo "<li><input type=\"radio\" checked=\"checked\" name=\"clipart\" id=\"ca".$i."\" value=\"".$i."\" /><label for=\"ca".$i."\"><img src=\"images/clipart/".$i.".jpg\" /></label></li>";
									} else {
										echo "<li><input type=\"radio\" name=\"clipart\" id=\"ca".$i."\" value=\"".$i."\" /><label for=\"ca".$i."\"><img src=\"images/clipart/".$i.".jpg\" /></label></li>";
									}
								}			    
						    ?>							
						</ul>
            <div class="graphicsby">Clipart courtesy of<a href="http://graphicsfactory.com">GraphicsFactory.com</a></div>
						<label>Your Name</label><input type="text" id="firstname" name="firstname" onfocus="removeText(this)" onblur="resetText(this)" value="<?php if(empty($_POST['firstname'])){ echo "First Name"; } else { echo stripslashes($_POST['firstname']); }?>" class="name"/><input type="text" onfocus="removeText(this)" onblur="resetText(this)" value="<?php if(empty($_POST['surname'])){ echo "Last Name"; } else { echo stripslashes($_POST['surname']); }?>" class="name" id="surname" name="surname" /><label for="rb5" class="rdcblabel makeanon" ><input type="checkbox" name="anonymous" value="yes" id="rb5" class="radiobutton" />Make Anonymous</label>
						<label class="pb20">
            <?php
             if(!$countrySelected) {
                  echo "<span style=\"color:red\">* Your Location</span>"; 
                } else {
                  echo "* Your Location";
                }    
            
            ?>
            </label><input type="text" onfocus="removeText(this)" onblur="resetText(this)" value="<?php if(empty($_POST['citytown'])) { echo "Town"; } else { echo stripslashes($_POST['citytown']);}?>" id="citytown" name="citytown" class="name"/>
						<select class="name" id="country" name="country">
							<?php echo $countryOptions; ?>
						</select>
           	<hr/>
						<label>
              <?php
                if(!$identicalEmails) {
                  echo "<span style=\"color:red\">* Email</span>"; 
                } else {
                  echo "* Email";
                } 
              ?>
            </label><input type="text" id="email" name="email" value="<?php echo stripslashes($_POST['email']); ?>" />
						<label>
              <?php
                if(!$identicalEmails) {
                  echo "<span style=\"color:red\">* Confirm Email</span>"; 
                } else {
                  echo "* Confirm Email";
                } 
              ?>            
            </label><input type="text" id="emailconfirm" name="emailconfirm" value="<?php echo stripslashes($_POST['emailconfirm']); ?>" />
						<br/>											
						<img class="captcha" alt="Captcha" src="securimage/securimage_show.php?sid=<?php echo md5(uniqid(time())); ?>" id="image" />
						<!-- Changed Class To Allow Styling -->
              <div class="captcha_button">
                <a href="#" onclick="document.getElementById('image').src = 'securimage/securimage_show.php?sid=' + Math.random(); return false">Try another code</a></div>
            <label>
              <?php
              if(!$verifiedCode) {
              echo "<span style=\"color:red\">* Verify Code</span>";
              } else {
              echo "* Verify Code";
              }
              ?>
            </label><input name="code" id="code" class="field" type="text" />						
						<hr/>
						<label id="cb3" class="rdcblabel agreements" ><input name="agree" value="yes" type="checkbox" id="cb3" class="checkbox"/>
              <?php
              if(!$agreementCheckbox) {
              echo "<span style=\"color:red\">*I agree to the
              <a href=\"terms.php\">Terms &amp; Conditions</a>, 
							<a href=\"codeofethics.php\">Code of Ethics</a> and 
							<a href=\"privacy.php\">Privacy Policy</a></span>";
              } else {
              echo "*I agree to the
              <a href=\"terms.php\">Terms &amp; Conditions</a>, 
							<a href=\"codeofethics.php\">Code of Ethics</a> and 
							<a href=\"privacy.php#\">Privacy Policy</a>";
              }
              ?>          
            </label>
						<p class="thankentry">Thanks for your entry. Be assured all entries are checked by our readers before appearing on page.</p>
						<input type="submit" class="button" value="Submit"/>
						
					</form>				
				</li>